version 14
set more off
set seed 1234

***************************************************************************************************
* THIS ROUTINE GENERATES FIGURE II PANELS C-F OF WASEEM (2019) RESTAT
***************************************************************************************************

use				"$project_data\ExemptionCutoff_06_11.dta",clear

/* BINNING DATA */

local			var="seinc"
local			lbound=80000
local			ubound=500000
local 			binsize=20000
local 			nbin=(`ubound'-`lbound')/`binsize'			
local 			mf=`binsize'/1000							
keep 			`var' regnor year treat regnor
g 				double z0=`var'
g 				z1=F1.`var'
g 				logchange=log(z1/z0)
keep 			if z0>80000 & z0<=500000
qui				sum logchange,d
drop			if (logchange<r(p1) | logchange>r(p99))
g 				bin=ceil(`var'/`binsize')
replace 		bin=bin*`mf'

/* GENERATING BINNED SCATTER PLOTS (DIFFERENCE-IN-DIFFERENCES) */

forvalues		y=2008/2010 {
				local m=substr("`y'",3,2)
g				treat_`m'=(year==`y' & treat==1)
g				cdellogincdd_`m'=0
g				se_`m'=0
g				cil_`m'=0
g				cih_`m'=0
}
g				cdellogincdd_0910=0
g				se_0910=0
g				trend=1
local			i=1
forvalues		y=2007/2011 {
local			i=`i'+1
replace			trend=`i' if year==`y'
}
g				treat_after=(treat==1 & year>2008)
forvalues		b=100(20)500 {
					qui reg logchange trend treat treat_09 treat_10 if bin==`b', cluster(regnor)
					forvalues y=2009/2010 {
						local m=substr("`y'",3,2)
						replace cdellogincdd_`m'=_b[treat_`m'] if bin==`b'
						replace cil_`m'=_b[treat_`m']-1.96*_se[treat_`m'] if bin==`b'
						replace cih_`m'=_b[treat_`m']+1.96*_se[treat_`m'] if bin==`b'
					}
					qui lincom treat_09+treat_10
					replace cdellogincdd_0910=r(estimate) if bin==`b'
					replace se_0910=r(se) if bin==`b'
}

*PLACEBO

forvalues		b=100(20)500 {
				qui reg	logchange trend treat treat_08 treat_09 treat_10 if bin==`b', cluster(regnor)
				replace cdellogincdd_08=_b[treat_08] if bin==`b'
				replace cil_08=_b[treat_08]-1.96*_se[treat_08] if bin==`b'
				replace cih_08=_b[treat_08]+1.96*_se[treat_08] if bin==`b'
}

* AGGREGATE

g 				cil_0910=cdellogincdd_0910-1.96*se_0910 
g 				cih_0910=cdellogincdd_0910+1.96*se_0910 

/* 2009 */

bys				bin year treat:g index=_n
#d				;
twoway  		(rarea cil_09 cih_09 bin if bin>80 & bin<=500 & index==1,sort color(gs13))
				(connected  cdellogincdd_09 bin if bin>80 & bin<=500 & index==1,sort clcolor(red) mcolor(red) msymbol(O) msize(large) lwidth(thick))
				(pcarrowi -0.3 170 -0.3 100, lcolor(black) mcolor(black))
				(pcarrowi -0.3 230 -0.3 300, lcolor(black) mcolor(black))
				(pcarrowi 0.3 420 0.3 400, lcolor(black) mcolor(black))
				(pcarrowi 0.3 480 0.3 500, lcolor(black) mcolor(black)),
				xtitle(Self-Employment Income in PKR 000s) xtitle(, alignment(top))
				xlabel(100(50)500)
				xline(300, lcolor(maroon) lwidth(thick) lpattern(longdash))
				xline(400 500, lpattern(dash) lcolor(gs5))
				ytitle(Difference-in-Differences Coefficient) yscale(titlegap(*10))
				ylabel(-0.4(0.2)0.4)
				text(0.3 450 "Not-to-zero""tax change")
				text(-0.3 200 "To-zero""tax changes")
				legend(region(style(none)) label(1 "95% Confidence Interval") label(2 "Coefficient") 
				rows(1) order(2 1)) 
				graphregion(fcolor(white) style(none) color(white) margin(0 2 0 2)) bgcolor(white);
				graph export "$project_graph\FigureIIPanelD.eps", replace;
#d 				cr

/* 2010 */

#d				;
twoway  		(rarea cil_10 cih_10 bin if bin>80 & bin<=500 & index==1,sort color(gs13))
				(connected  cdellogincdd_10 bin if bin>80 & bin<=500 & index==1,sort clcolor(red) mcolor(red) msymbol(O) msize(large) lwidth(thick))
				(pcarrowi -0.3 170 -0.3 100, lcolor(black) mcolor(black))
				(pcarrowi -0.3 230 -0.3 350, lcolor(black) mcolor(black))
				(pcarrowi 0.3 420 0.3 400, lcolor(black) mcolor(black))
				(pcarrowi 0.3 480 0.3 500, lcolor(black) mcolor(black)),
				xtitle(Self-Employment Income in PKR 000s) xtitle(, alignment(top))
				xlabel(100(50)500)
				xline(300, lcolor(maroon) lwidth(thick) lpattern(longdash))
				xline(350, lcolor(green) lwidth(thick) lpattern(longdash))
				xline(400 500, lpattern(dash) lcolor(gs5))
				ytitle(Difference-in-Differences Coefficient) yscale(titlegap(*10))
				ylabel(-0.4(0.2)0.4)
				text(0.3 450 "Not-to-zero""tax change")
				text(-0.3 200 "To-zero""tax changes")
				legend(region(style(none)) label(1 "95% Confidence Interval") label(2 "Coefficient") 
				rows(1) order(2 1)) 
				graphregion(fcolor(white) style(none) color(white) margin(0 2 0 2)) bgcolor(white);
				graph export "$project_graph\FigureIIPanelE.eps", replace;
#d 				cr

/* 2010-11 */

#d				;
twoway  		(rarea cil_0910 cih_0910 bin if bin>80 & bin<=500 & index==1,sort color(gs13))
				(connected  cdellogincdd_0910 bin if bin>80 & bin<=500 & index==1,sort clcolor(red) mcolor(red) msymbol(O) msize(large) lwidth(thick))
				(pcarrowi -0.3 170 -0.3 100, lcolor(black) mcolor(black))
				(pcarrowi -0.3 230 -0.3 300, lcolor(black) mcolor(black))
				(pcarrowi -0.3 300 -0.3 350, lcolor(black) mcolor(black))
				(pcarrowi 0.3 420 0.3 400, lcolor(black) mcolor(black))
				(pcarrowi 0.3 480 0.3 500, lcolor(black) mcolor(black)),
				xtitle(Self-Employment Income in PKR 000s) xtitle(, alignment(top))
				xlabel(100(50)500)
				xline(300, lcolor(maroon) lwidth(thick) lpattern(longdash))
				xline(350, lcolor(green) lwidth(thick) lpattern(longdash))
				xline(400 500, lpattern(dash) lcolor(gs5))
				ytitle(Difference-in-Differences Coefficient) yscale(titlegap(*10))
				ylabel(-0.4(0.2)0.6)
				text(0.3 450 "Not-to-zero""tax change")
				text(-0.3 200 "To-zero""tax changes")
				legend(region(style(none)) label(1 "95% Confidence Interval") label(2 "Coefficient") 
				rows(1) order(2 1)) 
				graphregion(fcolor(white) style(none) color(white) margin(0 2 0 2)) bgcolor(white);
				graph export "$project_graph\FigureIIPanelF.eps", replace;
#d 				cr

/* 2008 */

#d				;
twoway  		(rarea cil_08 cih_08 bin if bin>80 & bin<=500 & index==1,sort color(gs13))
				(connected  cdellogincdd_08 bin if bin>80 & bin<=500 & index==1,sort clcolor(red) mcolor(red) msymbol(O) msize(large) lwidth(thick)),
				xtitle(Self-Employment Income in PKR 000s) xtitle(, alignment(top))
				xlabel(100(50)500)
				xline(300, lcolor(maroon) lwidth(thick) lpattern(longdash))
				xline(350, lcolor(green) lwidth(thick) lpattern(longdash))
				xline(400 500, lpattern(dash) lcolor(gs5))
				ytitle(Difference-in-Differences Coefficient) yscale(titlegap(*10))
				ylabel(-0.4(0.2)0.4)
				legend(region(style(none)) label(1 "95% Confidence Interval") label(2 "Coefficient") 
				rows(1) order(2 1)) 
				graphregion(fcolor(white) style(none) color(white) margin(0 2 0 2)) bgcolor(white);
				graph export "$project_graph\FigureIIPanelC.eps", replace;
#d 				cr
